<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>修改商家密码</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>
<style>
	.my_but{
		line-height: 32px;
	    margin-left: 10px;
	    background-color: #ede6e6;
	    border: 1px solid #e1d2d2;
	    border-radius: 5px;
	    color: #86888b;
	}
</style>
	<body>
		<form class="layui-form" id="my_form" action="">
			<div class="layui-form-item" style="margin-top: 20px;">
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-block update_shurk">
					<input type="text" id='mobile' style="width: 80%;" name="mobile" lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" style="width:80%;" id='pwd' name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">验证码</label>
				<div class="layui-input-block update_shurk">
					<input type="text" style="width: 50%; float: left;" id='yzm' name="yzm" lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
					<a href="javascript:;" id="send_code"><button type="button"  class="my_but">获取验证码</button></a>
				</div>
			</div>
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" id='btn' type="button" lay-filter="formDemo">修改密码</button>
		    </div>
		  </div>
		</form>
	</body>
</html>
<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/layui/layui.all.js"></script>
<script>
	var onoff = true;
	//获取验证码
	$('#send_code').click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#mobile").val();
		
		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
			type:"post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('index/index/verify_code')}",
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						$('#send_code').text('发送验证码');
						onoff = true;
						//定时器停了
						clearInterval(timer);
					} else {
						$('#send_code').text(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})
	});
	
	
	//提交请求
	$('#btn').click(function() {
		var phone = $("#mobile").val();
		var input_code = $("#yzm").val();
		var pwd = $("#pwd").val();
		
		if(phone == '') {
			layer.msg('手机号码不能为空');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		if(input_code.trim() == '') {
			layer.msg('验证码不能为空');
			return;
		}
		if(pwd.trim() == '') {
			layer.msg('密码不能为空');
			return;
		}
		btn.disabled = true;
		setTimeout(function() {
			btn.disabled = false;
		}, 1500);
		
		//写入数据库
		$.ajax({
			type:"post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('agent/login/forget')}",
			//请求的过程中传递过去的参数 json
			data: $('#my_form').serialize(),//表单数据
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg, {
				  icon: 1,
				  time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function(){
					  if(data.code == 200) {
							var index = parent.layer.getFrameIndex(window.name);
				       		parent.layer.close(index); 
					  }
				}); 
			}
		})
	});
</script>